package cn.lingyangwl.agile.msg.push.controller;

import cn.lingyangwl.agile.common.security.annotation.InnerAuth;
import cn.lingyangwl.agile.msg.push.api.model.rqrs.MsgPushParam;
import cn.lingyangwl.agile.msg.push.core.propcess.MsgPushProcess;
import cn.lingyangwl.framework.core.response.Resp;
import com.github.yitter.idgen.YitIdHelper;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Api(tags = "消息推送")
@RestController
@RequestMapping("/msgPush")
public class MsgPushController {

    @Resource
    private MsgPushProcess msgPushHandler;


    /**
     * 需要做防刷操作, 只能是内网调用
     */
    @PostMapping("/")
    @InnerAuth
    public Resp<?> push(@RequestBody @Validated MsgPushParam msgPush) {
        msgPush.setHistoryId(null);
        msgPushHandler.push(msgPush, String.valueOf(YitIdHelper.nextId()));
        return Resp.ok();
    }
}
